<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport"
    content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
  <meta name="author" content="火星科技 http://mars3d.cn " />
  <meta name="apple-touch-fullscreen" content="yes" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  <meta name="format-detection" content="telephone=no" />
  <meta name="x5-fullscreen" content="true" />
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
  <!-- 标题及搜索关键字 -->
  <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
  <meta
    name="description"
    content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS" />

  <link rel="shortcut icon" type="image/x-icon" href="/img/favicon/favicon.ico" />
  <title>实时动态轨迹路线 | Mars3D | 三维地图 | 火星科技 | 合肥火星科技有限公司</title>

  <!--第三方lib-->
  <script
    type="text/javascript"
    src="/lib/include-lib.js"
    libpath="/lib/"
    include="jquery,layer,toastr,font-awesome,bootstrap,bootstrap-table,layer,haoutil,mars3d,es5-widget"></script>

  <link href="/css/style.css" rel="stylesheet" />
  <style>
    .fixed-table-container tbody .selected td {
      background-color: #3f4854a9;
    }
  </style>
</head>

<body class="dark">
  <div id="mars3dContainer" class="mars3d-container"></div>

  <!-- 面板 -->
  <div id="logView" class="infoview infoview-left"></div>

  <!-- 车辆列表 -->
  <div class="infoview">
    <table id="tableCar"></table>
  </div>

  <script src="/js/common.js"></script>
  <script src="./map.js"></script>

  <script type="text/javascript">
    "use script" //开发环境建议开启严格模式
    function addLog(log) {
      let logView = $("#logView")
      let oldhtml = logView.html()

      if (oldhtml.length < 500) {
        logView.html(oldhtml + log + "<br />")
      } else {
        logView.html(log + "<br />")
      }
    }

    function tabInit(data) {
      $("#tableCar").bootstrapTable({
        data: data,
        pagination: false,
        singleSelect: false,
        checkboxHeader: false,
        columns: [
          {
            title: "是否显示",
            field: "show",
            align: "center",
            checkbox: true,
            width: 50,
            formatter: function (value, row, index) {
              return {
                checked: true
              }
            }
          },
          {
            title: "序号",
            sortable: true,
            editable: false,
            align: "left",
            formatter: function (value, row, index) {
              return index + 1
            }
          },
          {
            field: "name",
            title: "车牌号"
          },
          {
            field: "type",
            title: "类型",
            formatter: function (value, row, index) {
              if (value == 1) {
                return "土方车"
              } else if (value == 2) {
                return "挖掘机"
              }
              return ""
            }
          },
          {
            title: "操作",
            align: "center",
            width: 80,
            events: {
              "click .remove": function (e, value, row, index) {
                const graphic = graphicLayer.getGraphicById(row.id)
                graphicLayer.removeGraphic(graphic)
                removeTableItem(row.id)
              },
              "click .edit": function (e, value, row, index) {
                const graphic = graphicLayer.getGraphicById(row.id)
                showEditor({ graphic })
              }
            },
            formatter: function (value, row, index) {
              return [
                '<a class="edit" href="javascript:void(0)" title="编辑"><i class="fa fa-edit"></i></a>&nbsp;&nbsp;',
                '<a class="remove" href="javascript:void(0)" title="删除"><i class="fa fa-trash"></i></a>'
              ].join("")
            }
          }
        ],
        //定位车辆区域
        onClickRow: function (row) {
          flyToModel(row.id)
        },
        //勾选显示车辆
        onCheck: function (row) {
          onSelect(row.id, true)
        },
        //取消勾选显示车辆
        onUncheck: function (row) {
          onSelect(row.id, false)
        }
      })
    }

    eventTarget.on("carList", function (event) {
      tabInit(event.tableData)
    })

    eventTarget.on("showPath", function (event) {
      addLog(event.path)
    })

    eventTarget.on("removeCar", function (event) {
      removeTableItem(event.id)
    })
    //附加：激活属性编辑widget【非必需，可以注释该方法内部代码】
    let timeTik
    function showEditor(e) {
      const graphic = e.graphic
      clearTimeout(timeTik)

      // if (!graphic._conventStyleJson) {
      //   graphic.options.style = graphic.toJSON().style //因为示例中的样式可能有复杂对象，需要转为单个json简单对象
      //   graphic._conventStyleJson = true //只处理一次
      // }

      let plotAttr = es5widget.getClass("widgets/plotAttr/widget.js")
      if (plotAttr && plotAttr.isActivate) {
        plotAttr.startEditing(graphic)
      } else {
        es5widget.activate({
          map: map,
          uri: "widgets/plotAttr/widget.js",
          name: "属性编辑",
          graphic: graphic
        })
      }
    }

    function removeTableItem(id) {
      $("#tableCar").bootstrapTable("remove", { field: "id", values: id })
    }
  </script>
</body>

</html>